package com.entidades;

import java.io.Serializable;
import java.util.Date;

import javax.annotation.Resource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Email implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource(lookup = "Projeto2POD_Email")
	private Session mailSession;

	public Email() {
		// TODO Auto-generated constructor stub

	}

	public void send(String to, String subject, String body) {
		MimeMessage message = new MimeMessage(mailSession);
		try {

			message.setFrom(new InternetAddress(mailSession.getProperty("projeto2pod@gmail.com")));
			InternetAddress[] address = { new InternetAddress(to) };
			message.setRecipients(Message.RecipientType.TO, address);
			message.setSubject(subject);
			message.setSentDate(new Date());
			message.setText(body);

			Transport.send(message);
		} catch (MessagingException ex) {
			ex.printStackTrace();
		}
	}

}
